/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.sd.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.sd.entity.MsgManager;
import com.jeesite.modules.sd.service.MsgManagerService;

/**
 * 消息管理，记录短信发送信息Controller
 * @author ysj
 * @version 2020-08-03
 */
@Controller
@RequestMapping(value = "${adminPath}/sd/msgManager")
public class MsgManagerController extends BaseController {

	@Autowired
	private MsgManagerService msgManagerService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public MsgManager get(String id, boolean isNewRecord) {
		return msgManagerService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("sd:msgManager:view")
	@RequestMapping(value = {"list", ""})
	public String list(MsgManager msgManager, Model model) {
		model.addAttribute("msgManager", msgManager);
		return "modules/sd/msgManagerList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("sd:msgManager:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<MsgManager> listData(MsgManager msgManager, HttpServletRequest request, HttpServletResponse response) {
		msgManager.setPage(new Page<>(request, response));
		Page<MsgManager> page = msgManagerService.findPage(msgManager);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("sd:msgManager:view")
	@RequestMapping(value = "form")
	public String form(MsgManager msgManager, Model model) {
		model.addAttribute("msgManager", msgManager);
		return "modules/sd/msgManagerForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("sd:msgManager:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated MsgManager msgManager) {
		msgManagerService.save(msgManager);
		return renderResult(Global.TRUE, text("保存消息管理，记录短信发送信息成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("sd:msgManager:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(MsgManager msgManager) {
		msgManagerService.delete(msgManager);
		return renderResult(Global.TRUE, text("删除消息管理，记录短信发送信息成功！"));
	}
	
}